package com.briup.ch01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/11/5
 * @Description:
 */
public class ConnectionTest {
    public static void main(String[] args) {
        //1.反射实现类加载
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        //2.通过驱动管理器获得连接对象
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/briup", "briup", "briup");
            System.out.println(connection);
            System.out.println(connection.getAutoCommit());
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            if(connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
